<template>
	<view class="label-input">
		<!-- 显示 -->
		<view class="uni-list-cell wrap" v-if="my_data.data_type == 0">
			<!-- <label>{{ my_data.title || '' }}</label> -->
			<label><text v-html="my_data.title || '' "></text></label>
			<text class="only-show" v-html=" my_data.value || ''"></text>
		</view>

		<!--  #ifdef  APP-PLUS || MP-WEIXIN -->
		<!-- 单行输入 -->
		<view
			class="uni-list-cell wrap"
			v-if="(my_data.input_type == 0 || my_data.input_type == null || my_data.input_type == 2) && my_data.data_type == 1 && inkey != 'location_id'"
		>
			<view class="justify_content">
				<!-- <label class="speech" @click="press">{{ my_data.title || '' }}</label> -->
				<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
				<!-- 计算按钮 -->
				<button type="warn" plain="true" class="width-auto get-location count_button" v-if="my_data.data" @click="count2">计算</button>
			</view>

			<view class="uni-flex">
				<textarea maxlength="-1" auto-height class="width-a100" type="text" :value="my_data.value" @blur="changeVal" placeholder-class="tips" placeholder="请输入" />

				<button type="primary" plain="true" class="width-auto get-location" v-if="my_data.input_type == 2" @click="getLocation">获取位置</button>
			</view>
		</view>
		<!-- 单行输入 地理位置 -->
		<view class="uni-list-cell wrap" v-if="(my_data.input_type == 0 || my_data.input_type == null) && my_data.data_type == 1 && inkey == 'location_id'">
			<!-- <label class="speech" @click="press">{{ my_data.title || '' }}</label> -->
			<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
			<view class="uni-flex">
				<input class="width-a100" type="text" v-model="locationAddr" @blur="changeVal" placeholder-class="tips" placeholder="请输入" />
				<text class="width-auto location">({{ location.length == 2 ? location[0] + ',' + location[1] : '' }})</text>
				<button type="primary" plain="true" class="width-auto get-location" v-if="inkey == 'location_id'" @click="getLocation">获取位置</button>
			</view>
		</view>

		<!--  #endif -->

		<!--  #ifdef  H5 -->
		<!-- 单行输入 -->
		<view
			class="uni-list-cell wrap"
			v-if="(my_data.input_type == 0 || my_data.input_type == null || my_data.input_type == 2) && my_data.data_type == 1 && inkey != 'location_id'"
		>
			<view class="justify_content">
				<!-- <label class="speech" @click="press">{{ my_data.title || '' }}</label> -->
				<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
				<!-- 计算按钮 -->
				<button type="warn" plain="true" class="width-auto get-location count_button" v-if="my_data.data" @click="count2">计算</button>
			</view>
			<view class="uni-flex">
				<textarea maxlength="-1" auto-height class="width-a100" type="text" v-model="my_data.value" @change="changeVal" placeholder-class="tips" placeholder="请输入" />
				<!-- <button type="warn" plain="true" class="width-auto get-location count_button" v-if="my_data.data" @click="count2">计算</button> -->
				<button type="primary" plain="true" class="width-auto get-location" v-if="my_data.input_type == 2" @click="getLocation">获取位置</button>
			</view>
		</view>
		<!-- 单行输入 地理位置 -->
		<view class="uni-list-cell wrap" v-if="(my_data.input_type == 0 || my_data.input_type == null) && my_data.data_type == 1 && inkey == 'location_id'">
			<!-- <label class="speech" @click="press">{{ my_data.title || '' }}</label> -->
			<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
			<view class="uni-flex">
				<input class="width-a100" type="text" v-model="locationAddr" @change="changeVal" placeholder-class="tips" placeholder="请输入" />
				<text class="width-auto location">({{ location.length == 2 ? location[0] + ',' + location[1] : '' }})</text>
				<button type="primary" plain="true" class="width-auto get-location" v-if="inkey == 'location_id'" @click="getLocation">获取位置</button>
			</view>
		</view>

		<!--  #endif -->

		<!-- 	单行输入 地理位置
		<view class="uni-list-cell wrap" v-if="(my_data.input_type == 0 || my_data.input_type == null) && my_data.data_type == 1 && inkey == 'location_id'">
			<label class="speech" @click="press">{{ my_data.title || '' }}</label>
			<view class="uni-flex">
				<input class="width-a100" type="text" v-model="locationAddr" @input="changeVal" placeholder-class="tips" placeholder="请输入" />
				<text class="width-auto location">({{ location.length == 2 ? location[0] + ',' + location[1] : '' }})</text>
				<button class="width-auto get-location" v-if="inkey == 'location_id'" @click="getLocation">获取位置</button>
			</view>
		</view> -->

		<!-- 时间选择 -->
		<view class="uni-list-cell wrap" v-if="my_data.input_type == 1 && my_data.data_type == 1">
			<!-- <label class="speech">{{ my_data.title || '' }}</label> -->
			<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
			<view class="width-a100">
				<picker mode="time" :value="initTime" @change="bindTimeChange" @cancel="clear_value">
					<input class="width-a100" type="text" v-model="showTime" disabled placeholder-class="tips" placeholder="请输入" />
				</picker>
			</view>
		</view>

		<!-- 日期选择 -->

		<view class="uni-list-cell wrap" v-if="my_data.input_type == 3">
			<view class="uni-flex">
				<!-- <label class="uni-list-cell-left">{{ my_data.title }}</label> -->
				<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
				<view class="uni-list-cell-db" style="flex: 2;align-items: center;">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" @cancel="clear_value">
						<view class="color-blue" v-if="data.value && data.value.length > 9 && !isNaN(data.value)">
							<!-- 当data.value有时间戳的时候 -->
							<view class="uni-input inp_padd">{{ date }}</view>
						</view>
						<view class="color-blue" v-else-if="isNaN(data.value)">
							<view class="uni-input inp_padd">{{data.value}}</view>
						</view>
						<view class="color-blue" v-else>
							<!-- 当data.value没有值为空时,显示提示 -->
							<view class="uni-input inp_padd">--请选择--</view>
						</view>
					</picker>
			
				</view>
			</view>
		</view>

		<!-- 单选 -->
		<!-- <picker class="uni-list-cell wrap" mode="selector"  v-if="my_data.data_type == 2" :range="radioList" @change="radioChange"  >
			<view>
				<view class="uni-list-cell-navigate">
					<label>{{ my_data.title || '' }}</label>
					<text class="textClo">{{ radioVal || '--请选择--' }}</text>
				</view>
			</view>
		</picker> -->

		<view class="uni-list-cell wrap" v-if="my_data.data_type == 2">
			<view class="uni-flex">
				<!-- <label class="uni-list-cell-left">{{ my_data.title }}</label> -->
				<label class="speech" @click="press"><text v-html=" my_data.title || ''"></text></label>
				<view class="uni-list-cell-db uni-navigate-right" style="flex: 2;align-items: center;">
					<picker mode="selector" @change="radioChange" :range="radioList">
						<view class="color-blue ">
							<view class="uni-input inp_padd">{{ radioVal || '--请选择--' }}</view>
						</view>
					</picker>
				</view>
			</view>
		</view>

		<!-- 多选 -->
		<view class="uni-list-cell wrap" hover-class="uni-list-cell-hover" v-if="my_data.data_type == 3" @click="goCehckbox('headweters')">
			<view class="uni-list-cell-navigate uni-navigate-right wrap uni-flex" style=" flex-wrap:wrap;text-align: center;">
				<!-- <label>{{ my_data.title || '' }}</label> -->
				<label><text v-html="my_data.title || '' "></text></label>
				<text class="textClo width-a100">{{ showVal || '--请选择--' }}</text>
			</view>
		</view>

		<!-- 图片 -->
		<view class="uni-list-cell wrap" v-if="my_data.data_type == 5">
			<!-- <label>{{ my_data.title || '' }}</label> -->
			<label><text v-html="my_data.title || '' "></text></label>
			<view class="uni-flex">
				<view class="width-a100"><image :src="my_data.value" v-if="my_data.value" @click="showImg"></image></view>
				<button type="primary" plain="true" class="width-auto select-img" @click="selectImg">选择图片</button>
			</view>
		</view>

		<!-- 显示图片 -->
		<view class="uni-list-cell wrap" v-if="my_data.data_type == 8">
			<!-- <label>{{ my_data.title || '' }}</label> -->
			<label><text v-html="my_data.title || '' "></text></label>
			<view class="uni-flex">
				<view class="width-a100"><image :src="my_data.value" v-if="my_data.value" @click="showImg"></image></view>
			</view>
		</view>

		<!-- 电子签名 -->
		<view class="uni-list-cell wrap" v-if="my_data.data_type == 7">
			<!-- <label>{{ my_data.title || '' }}</label> -->
			<label><text v-html="my_data.title || '' "></text></label>
			<view class="uni-flex">
				<view class="width-a100"><image :src="my_data.value" v-if="my_data.value" @click="showImg"></image></view>
				<button type="primary" plain="true" class="width-auto select-img" @click="goSignature">电子签名</button>
			</view>
		</view>

		<!-- 多行输入 -->
		<view class="uni-list-cell more-column" v-if="my_data.data_type == 6" @touchend="pressEnd">
			<!-- <label>{{ my_data.title || '' }}</label> -->
			<label><text v-html="my_data.title || '' "></text></label>
			<view class="uni-flex">
				<view class="width-a100"><textarea maxlength="-1" type="number" v-model="my_data.value" @longpress="press" placeholder-class="tips" placeholder="请输入" /></view>
				<button type="primary" plain="true" class="width-auto get-location" v-if="my_data.input_type == 2" @click="getLocation">获取位置</button>
			</view>
		</view>

		<lims-popup ref="limsPopup"></lims-popup>
	</view>
</template>

<script>
/**
	*此次修改是根据vue的数据监听watch,当修改某一项数据的时候,传给父组件,父子组件数据同步
	*当所有的input的数据传进来后,会生成不同的input组件,
	*@my_data:每个组件对应一个值
	*@alldata:所有input值的集合
	*@inkey:input组件对应的键值
	
	*/
import utils from '../common/utils.js';
import RPN from '../common/rpn3.js';
import service from '../service.js';
import limsPopup from './lims-popup.vue';
import uniIcons from '@/components/uni-icons/uni-icons.vue';

export default {
	components: {
		limsPopup,
		uniIcons
	},
	name: 'label-input',
	props: {
		child_data: {
			type: Object,
			default() {
				return {
					data_type: 0,
					input_type: null,
					title: '',
					value: ''
				};
			}
		},
		alldata: {
			type: Object,
			default() {
				return {};
			}
		},
		commondata: {
			type: Object,
			default() {
				return {};
			}
		},
		inkey: {
			type: Number | String,
			default: ''
		},
		tabIndex: {
			type: Number | String,
			default: 0
		},
		oneData: {
			type: Object,
			default: null
		}
	},
	// watch: {
	//     child_data: {
	// 		handler(oldVal, newVal){
	// 			console.log('aacc11');
	// 			//this.countResult();
	// 		},
	// 		deep: true
	// 	}
	// },
	data() {
		const currentDate = this.getDate({
			format: true
		});
		return {
			all_data: this.alldata,
			my_data: this.child_data,
			num1: '',
			list: [],
			showVal: [], // 显示的值
			radioVal: '', // 单选的值
			radioList: [], // 单选的列表
			locationAddr: '', // 单选的地址
			initTime: '',
			showTime: '',
			location: [], // 地址坐标
			isStartSpeech: false,
			host: '',
			date: currentDate,
			fieldData: {},
			
		};
	},
	watch: {
		//监听prop传的value，如果父级有变化了，将子组件的myValue也跟着变，达到父变子变的效果
		child_data: {
			handler(newVal) {
				console.log(newVal, '-----prop----newval');
				this.my_data = newVal;
			},
			deep: true //深度监听
		},
		//监听组件生成的my_data中的数据产生的变化,发生变化就传到父组件
		my_data: {
			handler(newVal) {
				console.log(newVal, '-----newval');
				this.$emit('input_value', newVal, this.inkey);
			},
			deep: true //深度监听
		}
		// all_data:{
		// 	handler(newVal) {
		// 		 console.log(newVal,"--------------------------all_data-----------------------------");
		// 		 this.$emit('all_data',newVal);
		// 	},
		// 	 deep: true    //深度监听
		// }
	},
	computed: {
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},
	created() {
		if (this.my_data.input_type == '3' && this.my_data.value) {
			//console.log(this.data,'皮卡丘');
			this.date = this.get2Date(this.my_data.value);
		}
	},
	updated() {
		if (this.my_data.input_type == '3') {
			// console.log(this.my_data.value,"_____________________")
			this.date = this.get2Date(this.my_data.value);
		}
	},
	methods: {
		get2Date() {
			let dt = new Date(parseInt(this.my_data.value));
			//   yyyy-mm-dd
			let y = dt.getFullYear();
			let m = (dt.getMonth() + 1).toString().padStart(2, '0');
			let d = dt
				.getDate()
				.toString()
				.padStart(2, '0');
			let date = `${y}-${m}-${d}`;
			// console.log(date, '转换后的时间');
			return date;
		},
		//组件初始化,将参数生成不同的input
		init() {
			//this.host = service.getWebsite();

			console.log(this.tabIndex);
			//console.log(this.alldata);
			if (['1', '2', '3', '5', '6', '7'].indexOf(this.my_data.data_type) != -1) {
				if (this.tabIndex !== 0 && (this.my_data.value === '' || this.my_data.value == null)) {
					this.my_data.value = (this.oneData && this.oneData[this.inkey] && this.oneData[this.inkey].value) || '';
				}
			}

			// 位置输入
			if (this.my_data.data_type == 1 && this.inkey == 'location_id' && this.my_data.value) {
				this.location = [];
				let tempArr = this.my_data.value.split(/\(+|\)+/g);
				this.locationAddr = tempArr[0] || '';
				if (tempArr[1]) {
					this.location = tempArr[1].split(',');
				}
			}

			// 单选
			if (this.my_data.data_type == 2) {
				let num = this.my_data.value.indexOf('#');
				console.log(num, '--------num');

				let list2 = this.my_data.value.replace(/\|\-\|\-\|\-\|\-\|\-/g, '─ ─ ─ ─ ─├ ');
				let list3 = list2.replace(/\|\-\|\-\|\-\|\-/g, '─ ─ ─ ─├ ');
				let list4 = list3.replace(/\|\-\|\-\|\-/g, '─ ─ ─├ ');
				let list5 = list4.replace(/\|\-\|\-/g, '─ ─├ ');
				let list6 = list5.replace(/\|\-/g, '─├ ');
				console.log(list6);
				// let tempArr = this.data.value.substring(num + 1).replace(/\|-/g,'');
				let tempArr = list6.substring(num + 1);
				console.log(tempArr, '------tempArr');
				this.radioList = tempArr.split(',');

				console.log(this.radioList, '------this.radioList');

				let temp = this.my_data.value.split('#');
				let indexNum = Number(temp[0]);
				if (indexNum > 0) {
					this.radioVal = this.radioList[indexNum - 1];
				} else {
					this.radioVal = '--请选择--';
				}
				// console.log(this.radioVal,'------this.radioVal ' );

				//
				// let temp = this.data.value.split('#');
				// // console.log(temp,'temp');
				//
				// this.radioVal = this.radioList[temp[0]-1];
				//
			}

			// 多选
			if (this.my_data.data_type == 3) {
				let temp = this.my_data.value.split('#');
				// console.log(temp,"__________temp");
				let value = temp[1].split(',');
				// console.log( value ,"__________ value ");
				let tempArr = temp[0].split(',');
				// console.log(tempArr ,"__________ tempArr ");
				if (tempArr.length != 0) {
					let showVal = [];
					tempArr.forEach((item, index) => {
						if (value[item - 1]) showVal.push(value[item - 1]);
					});
					console.log(showVal);
					this.showVal = showVal.join(',');
				}
				value.forEach((item, index) => {
					this.list.push({ name: item, id: index + 1 });
				});
			}

			// 图片 
			// if (this.my_data.data_type == 5 || this.my_data.data_type == 7 || this.my_data.data_type == 8) {
			// 	if (typeof this.my_data.value == 'string' && this.my_data.value.indexOf('original_template') > -1) {
			// 		if (this.my_data.value.indexOf('http') !== 0) {
			// 			this.my_data.value = service.getWebsite() + this.my_data.value;
			// 			console.log(this.my_data.value);
			// 		}
			// 	}
			// }
			//注:修改这里是因为签名图片被修改后,app的显示图片没有同步,但是点击放大的却是正常的
			if (this.my_data.data_type == 5 || this.my_data.data_type == 7 || this.my_data.data_type == 8) {
				if (typeof this.my_data.value == 'string' && this.my_data.value.indexOf('original_template') > -1) {
					if (this.my_data.value.indexOf('http') !== 0) {
						console.log('---------------------------图片');
						console.log(this.my_data.value);
						let newvalue = service.getWebsite() + this.my_data.value;

						uni.downloadFile({
							url: newvalue, 
							success: res => {
								if (res.statusCode === 200) {
									console.log('下载成功');
									console.log(res);
									let url = res.tempFilePath;
									this.$set(this.my_data, 'value', url);
								}
							}
						});
					}
				}
			}

			// 时间
			if (this.my_data.input_type == 1 && this.my_data.data_type == 1) {
				let time = new Date();
				this.showTime = '';

				if (this.my_data.value) time = new Date(Number(this.my_data.value));
				this.initTime = this.addZero(time.getHours()) + ':' + this.addZero(time.getMinutes());
				if (this.my_data.value && time != 'Invalid Date') {
					this.showTime = this.initTime;
				}
			}

			if (this.my_data.data) {
				console.log('进入init--------------------this.my_data.data');
				let formulaArr = JSON.parse(decodeURIComponent(this.my_data.data));
				//console.log(formulaArr,"------formulaArr");
				formulaArr.forEach((item, index) => {
					//console.log(item,index,"------------item,index");
					if (item.type == 'field' && this.alldata[item.value]) {
						if (this.alldata[item.value].formulaObj == null) {
							this.alldata[item.value].formulaObj = {};
						}
						console.log('进入init--------------------formulaArr.forEach((item, index)');
						this.alldata[item.value].formulaObj[this.inkey] = {
							formulaArr: formulaArr,
							formulaFun: () => {
								// 时间
								if (this.my_data.input_type == 1 && this.my_data.data_type == 1) {
									let time = new Date();
									if (this.my_data.value) {
										let time = new Date(this.my_data.value);
										this.showTime = this.addZero(time.getHours()) + ':' + this.addZero(time.getMinutes());
									} else {
										this.showTime = '';
									}
								}
								this.countResult();
							}
						};
						// this.$set(this.alldata[item.value],this.alldata[item.value].formulaObj,this.alldata[item.value].formulaObj[this.inkey])
						console.log(this.alldata[item.value], item.value, '------------------------------------------');
						this.$emit('all_Date', this.alldata[item.value], item.value);
					}
				});
				// console.log(formulaArr, '______');
				// console.log(this.alldata,"进入init--------------------this.alldata ");
			}
		},
		// 添加零
		addZero(num) {
			if ((num + '').length == 1) num = '0' + num;
			return num;
		},
		// 语音处理
		press() {
			let _this = this;

			plus.speech.addEventListener(
				'end',
				function() {
					if (_this.inkey == 'location_id') {
						_this.setLocationVal();
					}
				},
				false
			);

			let options = {
				continue: true,
				engine: 'baidu'
			};

			this.isStartSpeech = true;
			let text = '';

			plus.speech.startRecognize(
				options,
				function(str) {
					if (str != null) text += str;
					let index = text.indexOf('。');
					text = text.substring(0, index);
					if (_this.inkey == 'location_id') {
						_this.locationAddr += text;
					} else {
						_this.my_data.value += text;
					}
				},
				function(e) {
					uni.showToast({ icon: 'none', title: '语音识别失败：' + e.message });
					_this.pressEnd();
				}
			);

			setTimeout(() => {
				this.pressEnd();
			}, 10000);
		},
		pressEnd() {
			if (this.isStartSpeech) {
				plus.speech.stopRecognize();
			}
			this.isStartSpeech = false;
		},
		// 计算时间
		bindTimeChange(e) {
			let value = e.target.value;
			console.log(value, '----时间------');
			let valueArr = value.split(':');
			let time = new Date();
			time.setHours(valueArr[0]);
			time.setMinutes(valueArr[1]);
			this.my_data.value = time.getTime();
			//console.log(this.my_data.value, '------this.my_data.value  当前时间戳--------');
			this.showTime = value;

			//输入时间后自动计算
			this.countResult();
		},
		// 跳到多选页面
		goCehckbox() {
			//console.log(this.list, '____list');
			//对list进行去重
			// let oldArr = this.list;
			// let allArr = [];
			// for(var i=0;i<oldArr.length;i++){
			// 　　var flag = true;
			// 　　for(var j=0;j<allArr.length;j++){
			// 　　　　if(oldArr[i].id == allArr[j].id){
			// 　　　　　　flag = false;
			// 　　　　};
			// 　　};
			// 　　if(flag){
			// 　　　　allArr.push(oldArr[i]);
			// 　　};
			// };
			// this.list = allArr;
			let oldArr = this.list;
			let hash = {};
			this.list = oldArr.reduce((preVal, curVal) => {
				hash[curVal.id] ? '' : (hash[curVal.id] = true && preVal.push(curVal));
				return preVal;
			}, []);
			//console.log(this.list);
			let list = JSON.stringify(this.list);

			let list2 = list.replace(/\|\-\|\-\|\-\|\-\|\-/g, '─ ─ ─ ─ ─├ ');
			let list3 = list2.replace(/\|\-\|\-\|\-\|\-/g, '─ ─ ─ ─├ ');
			let list4 = list3.replace(/\|\-\|\-\|\-/g, '─ ─ ─├ ');
			let list5 = list4.replace(/\|\-\|\-/g, '─ ─├ ');
			let list6 = list5.replace(/\|\-/g, '─├ ');

			//console.log(list,"-----");
			//console.log(list2,"2-----");
			//console.log(list4,"4-----");

			this.list = JSON.parse(list6);
			let param = utils.toParam({ title: this.my_data.title });
			//console.log(param);

			service.PAGE_DATA.push({ list: this.list, checkData: this.showVal });
			// 用微信开发者工具调试时,它最大支持5个页面,需要把下面注释掉
			// 其它的
			//#ifdef H5 ||APP-PLUS
			uni.navigateTo({
				url: './checkbox' + param
			});
			// #endif
			// 用微信开发者工具调试时,它最大支持5个页面,需要把下面注释放开
			//#ifdef MP-WEIXIN
			uni.redirectTo({
				url: './checkbox' + param
			});
			// #endif

			utils.setCallBack((data, ids) => {
				this.showVal = data.join(',');
				let tempArr = [];
				this.list.forEach(item => {
					tempArr.push(item.name);
				});
				this.my_data.value = ids.join(',') + '#' + tempArr.join(',');
				//console.log(this.my_data.value);
			});
		},

		//点击 "电子签名"或"上传图片"
		goSignature() {
			let handleImage = sourceType => {
				uni.chooseImage({
					count: 1,
					sourceType: [sourceType],
					success: res => {
						let newVal = res.tempFilePaths[0];
						console.log(res);
						//#ifdef H5
						//只在H5移动端生效
						//得到路径后,获取图片信息
						this.getImageInfo(newVal);
						//#endif

						// #ifdef APP-PLUS || MP-WEIXIN
						let oldVal = this.my_data.value;
						service.saveFile(newVal, oldVal).then(newPath => {
							this.my_data.value = newPath;
						});
						//#endif
					}
				});
			};
			let funs = [
				() => {
					handleImage('camera');
				},
				() => {
					handleImage('album');
				},
				() => {
					let param = utils.toParam({ title: this.my_data.title });
					uni.navigateTo({
						url: './e_signature' + param
					});
					utils.setCallBack(newVal => {
						let oldVal = this.my_data.value;
						service.saveFile(newVal, oldVal).then(newPath => {
							console.log(newPath);
							this.my_data.value = newPath;
						});
					});
				}
			];
			//console.log(this.my_data.value, '------this.my_data.value');
			this.$refs.limsPopup.popShow(['拍摄', '从手机相册选择', '手写'], funs);
		},

		//#ifdef H5
		//只在H5移动端生效
		// 获取图片信息
		getImageInfo(src) {
			let that = this;
			uni.getImageInfo({
				src,
				success(res) {
					//得到图片信息对图片进行处理
					if (res.width > 1025) {
						that.disImg(res);
					} else {
						// that.disImg(res)
						let newVal = res.path;

						let oldVal = that.my_data.value;
						service.saveFile(newVal, oldVal).then(newPath => {
							that.my_data.value = newPath;
						});
					}
				}
			});
		},
		//压缩图片
		disImg(res) {
			let obj = {
				width: 550,
				height: 750,
				quality: 1
			};
			var img = new Image();
			img.src = res.path;

			var that = this;
			// 默认按比例压缩
			var w = that.width,
				h = that.height,
				scale = w / h;
			w = obj.width || w;
			h = obj.height || w / scale;
			var quality = 1; // 默认图片质量为0.7
			//生成canvas
			var canvas = document.createElement('canvas');
			var ctx = canvas.getContext('2d');
			// 创建属性节点
			var anw = document.createAttribute('width');
			anw.nodeValue = w;
			var anh = document.createAttribute('height');
			anh.nodeValue = h;
			canvas.setAttributeNode(anw);
			canvas.setAttributeNode(anh);
			ctx.drawImage(img, 0, 0, w, h);
			// 图像质量
			if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
				quality = obj.quality;
			}
			// quality值越小，所绘制出的图像越模糊
			var base64 = canvas.toDataURL('image/jpeg', quality);
			// 回调函数返回base64的值

			let newVal = base64;
			let oldVal = that.my_data.value;
			service.saveFile(newVal, oldVal).then(newPath => {
				that.my_data.value = newPath;
			});
		},
		//#endif

		getLocation() {
			// #ifdef  H5
			let that = this;
			uni.chooseLocation({
				success: function(res) {
					console.log('位置名称：' + res.name);
					console.log('详细地址：' + res.address);
					console.log('纬度：' + res.latitude);
					console.log('经度：' + res.longitude);
					let long = res.longitude.toFixed(2);
					let lat = res.latitude.toFixed(2);
					//console.log(that.location);
					that.$set(that.location, 0, long);
					that.$set(that.location, 1, lat);
					//console.log(JSON.stringify(that.location));
					// uni.showToast({ icon: 'none', title: '获取成功 经度：' + long + '，纬度：' + lat });
					that.setLocationVal();
				}
			});

			//  #endif

			// plus.geolocation.getCurrentPosition((res)=>{
			// 	let long = res.coords.longitude.toFixed(2);
			// 	let lat = res.coords.latitude.toFixed(2);
			// 	this.location[0] = long;
			// 	this.location[1] = lat;
			// 	uni.showToast({icon: 'none', title: '获取成功 经度：'+ long +'，纬度：' + lat});
			// 	this.setLocationVal();
			// }, (e)=>{
			// 	uni.showToast({icon: 'none', title: e.message});
			// }, {
			// 	//coordsType: 'wgs84',
			// 	geocode: false
			// });

			// #ifdef  APP-PLUS || MP-WEIXIN
			uni.getLocation({
				// type: 'wgs84',
				success: res => {
					console.log(res);
					// let long = res.longitude.toFixed(2);
					// let lat = res.latitude.toFixed(2);
					let lat = res.latitude.toFixed(4);
					let long = res.longitude.toFixed(4);
					// this.location[0] = long;
					// this.location[1] = lat;
					this.$set(this.location, 0, long);
					this.$set(this.location, 1, lat);
					//console.log('当前位置的经度：' + res.longitude);
					//console.log('当前位置的纬度：' + res.latitude);
					//console.log(JSON.stringify(this.location));
					uni.showToast({ icon: 'none', title: '获取成功 经度：' + long + '，纬度：' + lat });
					this.setLocationVal();
				}
			});
			//  #endif
		},
		setLocationVal() {
			//console.log(JSON.stringify(this.location), '----------------');
			if (this.inkey == 'location_id') {
				let str = '';
				if (this.location.length != 0) {
					str = '(' + this.location.join(',') + ')';
				}
				this.my_data.value = this.locationAddr + str;
				//console.log(this.my_data.value,"123");
			} else {
				this.my_data.value = this.my_data.value + this.location.join(',');
				//console.log(this.my_data.value,"12356");
			}
		},
		radioChange(evt) {
			let index = evt.detail.value;
			this.radioVal = this.radioList[index];
			this.my_data.value = Number(index) + 1 + '#' + this.radioList.join(',');
			//console.log(index);
			//console.log(this.my_data.value);
		},
		selectImg() {
			uni.chooseImage({
				count: 1,
				//sizeType: ['original'],
				success: res => {
					let oldVal = this.my_data.value;
					let newVal = res.tempFilePaths[0];
					// #ifdef APP-PLUS || MP-WEIXIN
					service.saveFile(newVal, oldVal).then(newPath => {
						this.my_data.value = newPath;
					});
					//#endif

					//#ifdef H5
					this.getImageInfo(newVal);
					//#endif
				}
			});
		},
		showImg() {
			//console.log(this.data.value, '我是showImg中的value');
			uni.previewImage({
				current: 1,
				urls: [this.my_data.value]
			});
		},
		countResult(e) {
			//console.log("--------------------------进入countResult--------------------");
			const MIN = 60000;
			if (this.my_data.formulaObj) {
				for (let formulaKey in this.my_data.formulaObj) {
					let formulaItem = this.my_data.formulaObj[formulaKey];
					let arr = [];

					formulaItem.formulaArr.forEach((item, index) => {
						if (item.type == 'field') {
							this.fieldData = item.field_type === 0 ? this.commondata[item.value] : this.alldata[item.value];

							if (this.fieldData && this.fieldData.input_type == 1 && this.fieldData.data_type == 1) {
								// 时间
								let min = Math.floor(this.fieldData.value / MIN);
								arr.push(min);
							} else if (this.fieldData && !isNaN(Number(this.fieldData.value))) {
								// 普通输入

								let num = this.fieldData.value;

								arr.push(Number(this.fieldData.value));
							} else {
								arr.push(0);
							}
						} else {
							arr.push(item.value);
						}
					});
					//console.log(arr,"----------arr");
					arr.push('#');
					let rpn = new RPN.Rpn(arr.join(''));
					//console.log(arr.join(''));
					rpn.createRpn();

					try {
						//console.log("我进入result-----try");
						let result = rpn.calculate();

						let resultData = this.alldata[formulaKey];

						let oldVal = resultData.value;
						if (!isNaN(result)) {
							if (resultData.input_type == 1 && resultData.data_type == 1) {
								result = Math.floor(result * MIN);
								resultData.value = result;
								//console.log("我进入result***********************");
								//console.log(resultData.value);
							} else {
								if (resultData.double_len) {
									resultData.value = result.toFixed(resultData.double_len);
									//console.log("我进入resultData.double_len***********************");
									//console.log(resultData.value);
								} else {
									//console.log("我进入resultData***********************");
									resultData.value = result;
									//console.log(resultData.value);
								}
							}
						} else {
							this.alldata[formulaKey].value = 0;
						}
						if (oldVal !== result) {
							//console.log("--------------------------进入countResult-----oldVal !== result--------------------");
							formulaItem.formulaFun();
							//console.log(formulaItem,"--------------------------进入countResult-----formulaItem--------------------");
						}
					} catch (e) {
						console.log(e);
					}
				}
			}
		},
		changeVal(event) {
			//console.log(event);
			// #ifdef APP-PLUS || MP-WEIXIN
			this.my_data.value = event.detail.value;
			//console.log(this.my_data,"-------");
			//#endif

			if (this.inkey == 'location_id') {
				this.setLocationVal(event);
			} else {
				// this.countResult(event);
			}
		},
		getDate(type) {
			let date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();

			if (type === 'start') {
				year = year - 10;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},
		bindDateChange(e) {
			let value = e.target.value;
			let valueArr = value.split('-');
			//console.log(valueArr);
			let newdate = new Date();
			newdate.setFullYear(valueArr[0]);
			newdate.setMonth(valueArr[1] - 1);
			newdate.setDate(valueArr[2]);
			this.my_data.value = newdate.getTime().toString(); //需要上传的时间戳
			// console.log(this.data.value, 'data中的value');
			this.date = value; //显示用的日期
		},

		// count2() {
		// 	console.log("----------------进入count2---------------------");
		// 	const MIN = 60000;
		// 	let that = this;
		// 	uni.showLoading({
		// 	    title: '计算中...',
		// 	});
		// 	setTimeout(() => {
		// 		if (that.my_data.data) {
		// 			let formulaItem = JSON.parse(decodeURIComponent(that.my_data.data));
		// 			let arr = [];
		// 			formulaItem.forEach((item, index) => {
		// 				if (item.type == 'field') {
		// 					that.fieldData = item.field_type === 0 ? that.commondata[item.value] : that.alldata[item.value];
		// 					// console.log(that.fieldData, '------- fieldData ------');
		// 					// console.log(that.commondata[item.value], '----that.commondata[item.value]');
		// 					// console.log(that.alldata[item.value], '------that.alldata[item.value]');
		// 					if (that.fieldData && that.fieldData.input_type == 1 && that.fieldData.data_type == 1) {
		// 						// 时间
		// 						let min = Math.floor(that.fieldData.value / MIN);
		// 						arr.push(min);
		// 						// console.log(min, that.fieldData.value, '---------min');
		// 					} else if (that.fieldData && !isNaN(Number(that.fieldData.value))) {
		// 						// 普通输入
		// 						// console.log('我进了这里');
		// 						// console.log(that.fieldData, '-------fieldData.');
		// 						let num = that.fieldData.value;
		// 						// console.log(num, 'wo 是num');
		// 						// console.log(that.fieldData.value, '-------fieldData.value');
		// 						arr.push(Number(that.fieldData.value));
		// 						// console.log(arr, '--------arr');
		// 					} else {
		// 						arr.push(0);
		// 					}
		// 				} else {
		// 					arr.push(item.value);
		// 				}
		// 			});
		// 			arr.push('#');
		// 			let rpn = new RPN.Rpn(arr.join(''));
		// 			// console.log(arr.join(''));
		// 			rpn.createRpn();
		// 			let formulaKey = that.inkey;
		// 			try {
		// 				let result = rpn.calculate();
		// 				console.log(that.alldata);
		// 				// console.log(result, '______result');
		// 				console.log(formulaKey, 888);
		// 				let resultData = that.alldata[formulaKey];
		// 				// console.log(resultData, '______aaaaresultData');
		// 				let oldVal = resultData.value;
		// 				if (!isNaN(result)) {
		// 					// console.log(resultData.value,"----resultData.value----");
		// 					if (resultData.input_type == 1 && resultData.data_type == 1) {
		// 						result = Math.floor(result * MIN);
		// 						resultData.value = result;
		// 						// console.log(resultData.value,"----resultData.value----");
		// 					} else {
		// 						//国人系统添加了double_len,用来对计算结果进行几位数的保留
		// 						if (resultData.double_len) {
		// 							resultData.value = result.toFixed(resultData.double_len);
		// 						} else {
		// 							resultData.value = result;
		// 							// console.log(resultData.value,"----resultData.value新的----");
		// 						}
		// 					}
		// 				} else {
		// 					console.log(that.alldata);
		// 					console.log(formulaKey);

		// 					that.alldata[formulaKey].value = 0;
		// 				}
		// 				if (oldVal !== result) {
		// 					console.log("----------------进入count2---oldVal !== result--------------------");

		// 					// formulaItem.formulaFun();
		// 					// console.log(that.alldata);
		// 					// console.log(formulaKey);
		// 					// that.alldata[formulaKey].formulaFun();
		// 					if (that.my_data.input_type == 1 && that.my_data.data_type == 1) {
		// 						let time = new Date();
		// 						if (that.my_data.value) {
		// 							let time = new Date(that.my_data.value);
		// 							that.showTime = that.addZero(time.getHours()) + ':' + that.addZero(time.getMinutes());
		// 						} else {
		// 							that.showTime = '';
		// 						}
		// 					}
		// 					that.countResult();
		// 				}
		// 			} catch (e) {
		// 				// console.log('我进入了这里');
		// 				console.log(e);
		// 			}
		// 		}
		// 		 uni.hideLoading();
		// 	}, 500);

		// },
		count2() {
			const MIN = 60000;
			let that = this;
			uni.showLoading({
				title: '计算中...'
			});
			setTimeout(() => {
				if (that.my_data.data) {
					let formulaItem = JSON.parse(decodeURIComponent(that.my_data.data));
					console.log(formulaItem, '---------------------formulaItem');

					let arr = [];
					formulaItem.forEach((item, index) => {
						if (item.type == 'field') {
							//判断type ==field时,value为需要参与计算的数字
							// console.log(that,"---------------------当前that");
							that.fieldData = item.field_type === 0 ? that.commondata[item.value] : that.alldata[item.value];
							console.log(that.fieldData, '---------------------当前that.fieldData');
							if (that.fieldData && that.fieldData.input_type == 1 && that.fieldData.data_type == 1) {
								// 时间
								let min = Math.floor(that.fieldData.value / MIN);

								arr.push(min);
							} else if (that.fieldData && !isNaN(Number(that.fieldData.value))) {
								// 普通输入

								let num = that.fieldData.value;

								console.log(num, '---------------------num ');

								arr.push(Number(that.fieldData.value));
								// console.log(arr ,"---------------------arr1------------------- ");
							} else {
								arr.push(0);
								// console.log(arr ,"---------------------arr2------------- ");
							}
						} else {
							// console.log(item.value,"-------------------item.value---------else");
							arr.push(item.value);
						}
					});
					//循环结束后,得到一个数组,数组中每一个元素为计算公式的内容  例如: 1+1     ----则数组为["1","+","1"]
					arr.push('#');
					console.log(arr, '--------------------arr');
					//将数组转成计算公式, join()将数据转成字符串;
					let arrstr = arr.join('');
					console.log(arrstr, '--------------------arrstr');

					let rpn = new RPN.Rpn(arrstr);
					console.log(rpn, '---------------rpn-------------');
					rpn.createRpn();

					let formulaKey = that.inkey;
					try {
						//计算结果result
						let result = rpn.calculate();
						console.log(result, '---------------result计算结果--------------------');
						let resultData = that.alldata[formulaKey];
						console.log(resultData, '======resultData');
						let oldVal = resultData.value ? resultData.value : 0;
						console.log(this.my_data);
						console.log(oldVal, '----------------旧值');
						if (!isNaN(result)) {
							console.log('--------------------进入1');
							if (resultData.input_type == 1 && resultData.data_type == 1) {
								//为时间输入
								result = Math.floor(result * MIN);
								this.my_data.value = result;
							} else {
								//普通输入
								console.log('--------------------进入2');
								//国人系统添加了double_len,用来对计算结果进行几位数的保留
								if (resultData.double_len) {
									//当double_len存在时,对结果进行小数位保留计算
									this.my_data.value = result.toFixed(resultData.double_len);
								} else {
									if (result === 0) {
										this.my_data.value = '0';
									} else {
										this.my_data.value = result;
									}
								}
							}
						} else {
							console.log(that.alldata);
							console.log(formulaKey);

							that.alldata[formulaKey].value = 0;
							// this.$emit('getAllData', JSON.parse(JSON.stringify(that.alldata)));
						}
						// console.log("********************************");
						// console.log(oldVal );
						// console.log("-------------------------------");
						// console.log(result);
						// if (oldVal !== result) {
						//
						// console.log(that.alldata);
						// console.log(formulaKey);
						// console.log(that.alldata[formulaKey]);

						// that.alldata[formulaKey].formulaFun();
						// if (that.data.input_type == 1 && that.data.data_type == 1) {
						// 	let time = new Date();
						// 	if (that.data.value) {
						// 		let time = new Date(that.data.value);
						// 		that.showTime = that.addZero(time.getHours()) + ':' + that.addZero(time.getMinutes());
						// 	} else {
						// 		that.showTime = '';
						// 	}
						// }
						// that.count2();
						// console.log(111111111111111);
						// }
					} catch (e) {
						// console.log('我进入了这里');
						console.log(e);
					}
				}
				uni.hideLoading();
			}, 500);
		},

		clear_value() {
			let that = this;
			if (that.my_data.value) {
				uni.showModal({
					title: '提示',
					content: '是否清除时间日期?',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							console.log(that.my_data);
							that.my_data.value = '';
							that.showTime = '';
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
view {
	font-size: 38rpx;
}
.justify_content {
	display: flex;
	justify-content: space-between;
}
.uni-list-cell-navigate {
	padding: 0;
}

.uni-list-cell,
.uni-list-cell-navigate {
	justify-content: flex-start;
}

.wrap.uni-list-cell {
	/* align-items: start; */
	padding: 15upx 10upx !important;
	flex-wrap: wrap;

	view {
		width: 100%;
	}
}

.only-show {
	color: #999999;
}

.label-input label {
	flex: 0 0 auto;
	color: #555555;
	max-width: 90%;
}

.label-input input,
.label-input .time {
	border-bottom: 1px solid #666;
	padding: 0 15upx;
	flex: 1 1 100%;
	max-width: 100%;
}

.uni-list-cell text {
	margin-left: 10px;
}

.uni-list-cell.more-column {
	flex-direction: column;
}

.uni-list-cell.more-column {
	flex-direction: column;
	align-items: flex-start;
}

.uni-list-cell.more-column textarea {
	width: 100%;
	height: 180rpx;
	border: 1px solid #666;
	padding: 2px 5px;
	box-sizing: border-box;
}

.uni-list-cell-navigate text {
	margin-right: 30upx;
}

.location {
	font-size: 28upx;
}

image {
	height: 100upx;
	margin: 0 10upx;
	width: 200upx;
}
.textClo {
	color: #1c86ee;
	padding: 0 30px;
	flex: 1;
}
.select-img,
.get-location {
	font-size: 30upx;
	padding: 10upx 14upx;
	line-height: 2;
}

.get-location {
	margin-left: 10upx;
}

.uni-flex {
	align-items: center;
}

.tips {
	color: #cccccc;
}

.speech:active {
	color: #007aff;
}
.inp_padd {
	padding: 0 !important;
}
.uni-list-cell-left {
	font-size: 38rpx;
	padding-left: 0;
	padding-right: 50upx;
}
.color-blue {
	text-align: center;
	color: #1c86ee;
}
.count_button {
	margin: 0;
}
textarea{
	padding-left: 20rpx;
}
</style>
